<!DOCTYPE html>
<!--
This is a starter template page. Use this page to start your new project from
scratch. This page gets rid of all links and provides the needed markup only.
-->
<html>

<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>交易市场</title>
	<!-- Tell the browser to be responsive to screen width -->
	<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
	<link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.min.css">
	<!-- Font Awesome -->
	<link rel="stylesheet" href="../bower_components/font-awesome/css/font-awesome.min.css">
	<!-- Ionicons -->
	<link rel="stylesheet" href="../bower_components/Ionicons/css/ionicons.min.css">
	<!-- Theme style -->
	<link rel="stylesheet" href="../dist/css/AdminLTE.css">
	<!-- AdminLTE Skins. We have chosen the skin-blue for this starter
        page. However, you can choose any other skin. Make sure you
        apply the skin class to the body tag so the changes take effect. -->
	<link rel="stylesheet" href="../dist/css/skins/skin-blue.min.css">

	<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
	<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
	<!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->

	<!-- Google Font -->
	<link rel="stylesheet" href="https://fonts.useso.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
	<link rel="stylesheet" href="../dist/css/mycss.css">
	<script src="../dist/js/myjs.js"></script>
</head>
<!--
BODY TAG OPTIONS:
=================
Apply one or more of the following classes to get the
desired effect
|---------------------------------------------------------|
| SKINS         | skin-blue                               |
|               | skin-black                              |
|               | skin-purple                             |
|               | skin-yellow                             |
|               | skin-red                                |
|               | skin-green                              |
|---------------------------------------------------------|
|LAYOUT OPTIONS | fixed                                   |
|               | layout-boxed                            |
|               | layout-top-nav                          |
|               | sidebar-collapse                        |
|               | sidebar-mini                            |
|---------------------------------------------------------|
-->

<body class="hold-transition skin-blue sidebar-mini">
	<div class="wrapper">

		<!-- Main Header -->
		<header class="main-header">
		</header>
		<!-- Left side column. contains the logo and sidebar -->
		<aside class="main-sidebar">
			<!-- /.sidebar -->
		</aside>

		<!-- Content Wrapper. Contains page content -->
		<div class="content-wrapper">
			<!-- Content Header (Page header) -->
			<section class="content-header">
				<h1>
					首页
					<small>>用户中心>交易市场</small>
				</h1>
			</section>

			<!-- Main content -->
			<section class="content container-fluid">

				<!--------------------------
        | Your Page Content Here |
        -------------------------->
				<!--coded By Bobo 2017/7/13-->
				<div class="box">
					<div class="box-body">

						<div>
							<!-- Nav tabs -->


							<!-- Tab panes -->
							<div class="tab-content">
								<div role="tabpanel" class="tab-pane active">
									<table class="table table-hover c">

										<!--下面是查询框-->
										<div class="col-md-6 col-md-offset-3 col-sm-12">
											<div class="input-group">
												<input type="text" class="form-control" id="type" placeholder="输入类型">
												<span class="input-group-btn">
	                  <button class="btn btn-default" type="button" onclick="research_by_type()">
	             <span class="glyphicon glyphicon-search" aria-hidden="true"></span>
												</button>
												</span>
											</div>
											<!-- /input-group -->
										</div>
									</table>
								</div>
							</div>

							<!-- <div class="tab-content">
				<div role="tabpanel" class="tab-pane active">
					  <table class="table table-hover c">				
					  <div class="col-md-offset-5 col-md-5 col-sm-12">
					   <button type="button" class="btn btn-default pull-right block" onclick="dateup()">日期升</button>
					   <button type="button" class="btn btn-default pull-right block" onclick="datedown()">日期降</button>
					   <button type="button" class="btn btn-default pull-right block" onclick="moneyup()">金额升</button>
					   <button type="button" class="btn btn-default pull-right block" onclick="moneydown()">金额降</button>
					  </div>	
					  <br>
					</table>
				</div>
			   </div> -->

							<div class="tab-content">
								<div role="tabpanel" class="tab-pane active">
									<table class="table table-hover c">
										<tr>
											<div id="searchResult"></div>
										</tr>
									</table>
								</div>
							</div>


						</div>
					</div>
				</div>
		</div>






	</div>
	</div>
	<!-- /.box-body -->
	</div>
	</section>
	<!-- /.content -->
	</div>
	<!-- /.content-wrapper -->

	<!-- Main Footer -->
	<footer class="main-footer">
	</footer>
	<!-- Control Sidebar -->
	<aside class="control-sidebar control-sidebar-dark">
		<!-- Create the tabs -->
		<ul class="nav nav-tabs nav-justified control-sidebar-tabs">
			<li class="active"><a href="#control-sidebar-home-tab" data-toggle="tab"><i class="fa fa-home"></i></a></li>
			<li><a href="#control-sidebar-settings-tab" data-toggle="tab"><i class="fa fa-gears"></i></a></li>
		</ul>
		<!-- Tab panes -->
		<div class="tab-content">
			<!-- Settings tab content -->
			<div class="tab-pane" id="control-sidebar-settings-tab">
				<form method="post">
					<h3 class="control-sidebar-heading">General Settings</h3>

					<div class="form-group">
						<label class="control-sidebar-subheading">
              Report panel usage
              <input type="checkbox" class="pull-right" checked>
            </label>

						<p>
							Some information about this general settings option
						</p>
					</div>
					<!-- /.form-group -->
				</form>
			</div>
			<!-- /.tab-pane -->
		</div>
	</aside>
	<!-- /.control-sidebar -->
	<!-- Add the sidebar's background. This div must be placed
  immediately after the control sidebar -->
	<div class="control-sidebar-bg"></div>
	</div>
	<!-- ./wrapper -->

	<!-- REQUIRED JS SCRIPTS -->

	<!-- jQuery 3 -->
	<script src="../bower_components/jquery/dist/jquery.min.js"></script>
	<!-- Bootstrap 3.3.7 -->
	<script src="../bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
	<!-- AdminLTE App -->
	<script src="../dist/js/adminlte.js"></script>
	<script src="../dist/js/myjs.js"></script>
	<!-- Optionally, you can add Slimscroll and FastClick plugins.
     Both of these plugins are recommended to enhance the
     user experience. -->
	<script>
		/*
   *加载header、sider和footer
  */
		$(".main-header").load("mainheader.html");
		$(".main-sidebar").load("mainsider.html");
		$(".main-footer").load("../mainfooter.html");
		$(document).ready(function(){
        $(".target").removeClass("highlight");
      $(".market").addClass("highlight");
   });
		/*
		*
		*/
		$(document).ready(function () {
			$("#material1").hide();
			$("#upload").click(function () {
				$("#material1").show();
			});
			$("#dmaterial1").click(function () {
				$("#material1").hide();
			});
		});
	</script>
	<script>
		$(document).ready(function () {

		});
		function getCookie(objName) {//获取指定名称的cookie的值   
			var arrStr = document.cookie.split("; ");
			for (var i = 0; i < arrStr.length; i++) {
				var temp = arrStr[i].split("=");
				if (temp[0] == objName)
					return unescape(temp[1]);
			}
		}
		var hname = getCookie("hname");
		if (hname == "") {
			window.location.href = "login.html";
		}
		$("#hname").html(hname);

		var postBody = {
			type: $('#type').val()
		};
		$.ajax({
			type: 'POST',
			url: '/check/unsold/query',
			data: postBody,
			dataType: 'json',
			success: function (data) {
				//$("暂无满足要求的数据").appendTo("#searchResult");
				console.log("ajax" + JSON.stringify(data));
				function getJsonLength(jsonData) {
					var jsonLength = 0;
					for (var item in jsonData) {
						jsonLength++;
					}
					return jsonLength;
				}
				var jsonLength = getJsonLength(data);
				for (var o in data) {
					if (data[o].userId == getCookie("name")) {
						$('<div class="well well-lg">' +
							'<table class="table table-hover"><tbody><tr>' +
							'<td class="text-left"><strong>区块链追踪交易号&nbsp;&nbsp;</strong></td><td class="text-left" colspan="3"><span id="txid' + o + '">' + data[o].txid +
							'<tbody><tr><td class="text-left" hidden="hidden"><strong>编号<strong></td><td class="text-left" hidden="hidden"><span id="bianhao' + o + '">' + data[o].bianhao +
							'</span></td></tr></tbody>' +
							'<tbody><tr><td class="text-left"><strong>电子仓单编号</strong></td><td class="text-left"><span id="cangdanId' + o + '">' + data[o].cangdanId +
							'</span></td><td class="text-left"><strong>价值<strong></td><td class="text-left"><span id="money' + o + '">' + data[o].money +
							'</span></td><td class="text-left"><strong>持有人<strong></td><td class="text-left"><span id="userId' + o + '">' + data[o].userId +

							'</span></td></tr></tbody>' +
							'<tbody><tr><td class="text-left"><strong>品名/材质</strong></td><td class="text-left"><span id="pinming' + o + '">' + data[o].pinming +
							'</span>' + '/' + '<span id="caizhi' + o + '">' + data[o].caizhi +
							'</span></td><td class="text-left"><strong>规格</strong></td><td class="text-left"><span id="guige' + o + '">' + data[o].guige +
							'</span></td><td class="text-left"><strong>类型<strong></td><td class="text-left"><span id="type' + o + '">' + data[o].type +
							'</span></td></tr></tbody>' +

							'<tbody><tr><td class="text-left"><strong>产地<strong></td><td class="text-left"><span id="chandi' + o + '">' + data[o].chandi +
							'</span></td><td class="text-left"><strong>件数/重量</strong></td><td class="text-left"><span id="jianshu' + o + '">' + data[o].jianshu +
							'</span>' + '/' + '<span id="zhongliang' + o + '">' + data[o].zhongliang +
							'</span></td><td class="text-left"><strong>交割仓库</strong></td><td class="text-left"><span id="cangku' + o + '">' + data[o].cangku +

							'</span></td></tr></tbody></table><button class="btn disabled pull-right" id="' + o + '" onclick="buy(this)">购买</button></br></div></hr>').appendTo("#searchResult");
					}
					else {
						$('<div class="well well-lg">' +
							'<table class="table table-hover"><tbody><tr>' +
							'<td class="text-left"><strong>区块链追踪交易号&nbsp;&nbsp;</strong></td><td class="text-left" colspan="3"><span id="txid' + o + '">' + data[o].txid +
							'<tbody><tr><td class="text-left" hidden="hidden"><strong>编号<strong></td><td class="text-left" hidden="hidden"><span id="bianhao' + o + '">' + data[o].bianhao +
							'</span></td></tr></tbody>' +
							'<tbody><tr><td class="text-left"><strong>电子仓单编号</strong></td><td class="text-left"><span id="cangdanId' + o + '">' + data[o].cangdanId +
							'</span></td><td class="text-left"><strong>价值<strong></td><td class="text-left"><span id="money' + o + '">' + data[o].money +
							'</span></td><td class="text-left"><strong>持有人<strong></td><td class="text-left"><span id="userId' + o + '">' + data[o].userId +

							'</span></td></tr></tbody>' +
							'<tbody><tr><td class="text-left"><strong>品名/材质</strong></td><td class="text-left"><span id="pinming' + o + '">' + data[o].pinming +
							'</span>' + '/' + '<span id="caizhi' + o + '">' + data[o].caizhi +
							'</span></td><td class="text-left"><strong>规格</strong></td><td class="text-left"><span id="guige' + o + '">' + data[o].guige +
							'</span></td><td class="text-left"><strong>类型<strong></td><td class="text-left"><span id="type' + o + '">' + data[o].type +
							'</span></td></tr></tbody>' +

							'<tbody><tr><td class="text-left"><strong>产地<strong></td><td class="text-left"><span id="chandi' + o + '">' + data[o].chandi +
							'</span></td><td class="text-left"><strong>件数/重量</strong></td><td class="text-left"><span id="jianshu' + o + '">' + data[o].jianshu +
							'</span>' + '/' + '<span id="zhongliang' + o + '">' + data[o].zhongliang +
							'</span></td><td class="text-left"><strong>交割仓库</strong></td><td class="text-left"><span id="cangku' + o + '">' + data[o].cangku +

							'</span></td></tr></tbody></table><button class="btn btn-primary pull-right" id="' + o + '" onclick="buy(this)">购买</button></br></div></hr>').appendTo("#searchResult");
					}
				}
				if (jsonLength == 0) {
					$("#searchResult").html("暂无满足要求的数据,请稍后再试");
				}
			}


		});









		function research_by_type() {
			var postBody = {
				type: $('#type').val()
			};
			$.ajax({
				type: 'POST',
				url: 'check/unsold/query/by_type',
				data: postBody,
				dataType: 'json',
				success: function (data) {
					if (data != null) {
						window.location.href = "searchResult.html?type=" + $('#type').val();
						window.location.assign(encodeURI(myurl));
					} else {
						alert("没有搜索此类到结果");
					}
				}
			}).error(function (err) {
				console.log(err);
				alert(err.responseText + "错误");
			});
			console.log('research_by_type');
		};



		function buy(obj) {
			var num = obj.id;      //id就是定义的o

			var name = getCookie("name");
			if (name == "") {
				window.location.href = "login.html";
			}

			var istr = "#bianhao" + num;                   //全局的_id
			var hstr = "#userId" + num;                //全局的userId
			var tstr = "#txid" + num;                  //交易号
			var cstr = "#cangdanId" + num;             //仓单号

			if (name == $(hstr).html()) {
				alert("无法购买自己的资产");
			} else {
				var mymessage = confirm("请确认！您所购买资产的追踪号为：" + $(tstr).html());
				if (mymessage == true) {
					var postBody = {

						bianhao: $(istr).html(),
						//	state: $(pstr).html(),
						userId: $(hstr).html(),
						txid: $(tstr).html(),
						buyer: $("#name").html()
					};
					console.log(JSON.stringify(postBody));

					$.ajax({
						type: 'POST',
						url: '/check/buy/application',
						data: postBody,
						dataType: 'json',
						success: function (data) {
//							$('#' + num + '').replaceWith('<span class="pull-right" style="color:#00bfff;">购买成功</span>');
							alert(data.status);
							window.location.href = "market.html";
							//							alert("请求成功！正在等待受理");
							console.log("data success" + jsonstr);

						}
					});


				}
				else if (mymessage == false) {
					alert("交易取消!");
				}




			}
		}

		document.getElementById('name').innerHTML = name;
		function delCookie(name) {//为了删除指定名称的cookie，可以将其过期时间设定为一个过去的时间   
			var date = new Date();
			date.setTime(date.getTime() - 10000);
			document.cookie = name + "=a; expires=" + date.toGMTString();
		}
		function del_() {
			delCookie(name);
			delCookie(password);
			window.location.href = "index.html";
		}
		function login_out() {
			delCookie(getCookie("name"));
			setTimeout("window.location.href='login.html'", 1000);
		}
	</script>
</body>

</html>